package com.hibernate.rcache;

import com.hibernate.rcache.region.RcacheCollectionRegion;
import com.hibernate.rcache.region.RcacheEntityRegion;
import com.hibernate.rcache.strategy.NonStrictReadWriteRcacheEntityRegionAccessStrategy;
import com.hibernate.rcache.strategy.ReadOnlyRcacheEntityRegionAccessStrategy;
import com.hibernate.rcache.strategy.ReadWriteRcacheEntityRegionAccessStrategy;
import org.hibernate.cache.access.AccessType;
import org.hibernate.cache.access.CollectionRegionAccessStrategy;
import org.hibernate.cache.access.EntityRegionAccessStrategy;

import static org.hibernate.cache.access.AccessType.*;


public class RcacheAccessStrategyFactory {


    public EntityRegionAccessStrategy createEntityRegionAccessStrategy(RcacheEntityRegion rcacheEntityRegion, AccessType accessType) {
        if (READ_ONLY.equals(accessType)) {
            return new ReadOnlyRcacheEntityRegionAccessStrategy(rcacheEntityRegion, rcacheEntityRegion.getSettings());
        } else if (READ_WRITE.equals(accessType)) {
            return new ReadWriteRcacheEntityRegionAccessStrategy(rcacheEntityRegion, rcacheEntityRegion.getSettings());
        } else if (NONSTRICT_READ_WRITE.equals(accessType)) {
            return new NonStrictReadWriteRcacheEntityRegionAccessStrategy(
                    rcacheEntityRegion,
                    rcacheEntityRegion.getSettings()
            );
        }
        throw new IllegalArgumentException("unrecognized access strategy type [" + accessType + "]");
    }

    public CollectionRegionAccessStrategy createCollectionRegionAccessStrategy(RcacheCollectionRegion rcacheCollectionRegion, AccessType accessType) {
        return null;
    }
}
